package com.air.airbnb.modular.airbnb.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.air.airbnb.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.air.airbnb.modular.system.model.AirbnbDetails;
import com.air.airbnb.modular.airbnb.service.IAirbnbDetailsService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-12-06 17:31:47
 */
@Controller
@RequestMapping("/airbnbDetails")
public class AirbnbDetailsController extends BaseController {

    private String PREFIX = "/system/airbnbDetails/";

    @Autowired
    private IAirbnbDetailsService airbnbDetailsService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "airbnbDetails.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/airbnbDetails_add")
    public String airbnbDetailsAdd() {
        return PREFIX + "airbnbDetails_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/airbnbDetails_update/{airbnbDetailsId}")
    public String airbnbDetailsUpdate(@PathVariable Integer airbnbDetailsId, Model model) {
        AirbnbDetails airbnbDetails = airbnbDetailsService.selectById(airbnbDetailsId);
        model.addAttribute("item",airbnbDetails);
        LogObjectHolder.me().set(airbnbDetails);
        return PREFIX + "airbnbDetails_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return airbnbDetailsService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AirbnbDetails airbnbDetails) {
        airbnbDetailsService.insert(airbnbDetails);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer airbnbDetailsId) {
        airbnbDetailsService.deleteById(airbnbDetailsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AirbnbDetails airbnbDetails) {
        airbnbDetailsService.updateById(airbnbDetails);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{airbnbDetailsId}")
    @ResponseBody
    public Object detail(@PathVariable("airbnbDetailsId") Integer airbnbDetailsId) {
        return airbnbDetailsService.selectById(airbnbDetailsId);
    }
}
